package dao.impl;

import java.sql.SQLException;
import java.util.List;

import util.Pager;

import model.Product;
import model.ProductQuery;
import model.SaleOrder;
import model.SaleProduct;
import model.Shop;

import com.ibatis.sqlmap.client.SqlMapClient;

import dao.OrderManageDao;
import dao.ProManageDao;

public class OrderManageDaoImpl implements OrderManageDao {
	private SqlMapClient sqlMapClient;

	@Override
	public List<Shop> getClients(String attribute) throws SQLException {
		List<Shop> list =  this.sqlMapClient.queryForList("orderManageSQL.getClients",attribute);
		return list;
	}

	public SqlMapClient getSqlMapClient() {
		return sqlMapClient;
	}

	public void setSqlMapClient(SqlMapClient sqlMapClient) {
		this.sqlMapClient = sqlMapClient;
	}

	@Override
	public String getSerialByDate() throws SQLException {
		return (String)this.sqlMapClient.queryForObject("orderManageSQL.getSerial");
	}

	@Override
	public int saveSaleOrder(SaleOrder so) throws SQLException {
		return this.sqlMapClient.update("orderManageSQL.saveSaleOrder",so);
	}

	@Override
	public void saveSalePros(String serial, List<SaleProduct> salePros) throws SQLException {
		for(SaleProduct pro:salePros){
			pro.setSerial(serial);
			this.sqlMapClient.insert("orderManageSQL.saveSalePro", pro);
		}
	}

	@Override
	public Product getProductById(int id) throws SQLException {
		return (Product)this.sqlMapClient.queryForObject("orderManageSQL.getProduct", id);
	}

	@Override
	public Shop getShopById(int shopId) throws SQLException {
		return (Shop)this.sqlMapClient.queryForObject("orderManageSQL.getShop", shopId);
	}

	@Override
	public String getLabelNameById(String label) throws SQLException {
		return (String)this.sqlMapClient.queryForObject("orderManageSQL.getLabelName", label);
	}
	
	
	
}
